package com.hoshiicloud.user.controller.company;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.common.validate.ValidGroupAdd;
import com.hoshiicloud.common.validate.ValidGroupUpdate;
import com.hoshiicloud.user.entity.company.Settlement;
import com.hoshiicloud.user.service.company.ISettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 结算方式 前端控制器
 * </p>
 *
 * @author WGJ
 * @since 2019-04-22
 */
@RestController
@RequestMapping("/company/settele")
@Api(value = "结算方式管理", tags = {"结算方式操作接口"})
public class SettlementController {
    @Autowired
    private ISettlementService settEleService;

    /**
     * @param id
     * @return com.hoshiicloud.common.rpc.Response
     * @description: 根据id查询附件类型信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询",
            notes = "查询结算方式信息",
            produces = "application/json, application/rbac",
            consumes = "application/json, application/rbac")
    public Response findSettEleById(@PathVariable("id") Long id) {

        return Response.data(settEleService.getById(id));
    }

    /**
     * @param
     * @return com.hoshiicloud.common.rpc.Response
     * @description: 根据名称查询
     */
    @GetMapping("/find/{name}")
    @ApiOperation(value = "查询",notes = "根据名称查询结算方式信息",
            produces = "application/json, application/rbac",
            consumes = "application/json, application/rbac")
    public Response findSettEleByName(@PathVariable("name") String name) {

        Wrapper wrapper = Wrappers.<Settlement>query().lambda().eq(Settlement::getSettName, name);

        return Response.data(settEleService.getOne(wrapper));

    }

    /**
     * @param settlement
     * @return com.hoshiicloud.common.rpc.Response
     * @description: 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增",
            notes = "新增附件结算方式信息",
            produces = "application/json, application/rbac",
            consumes = "application/json, application/rbac")
    public Response saveSettEle(@RequestBody @Validated(value = ValidGroupAdd.class)  Settlement settlement) {

        return Response.data(settEleService.save(settlement));
    }

    /**
     * @param settlement
     * @return com.hoshiicloud.common.rpc.Response
     * @description: 修改
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改",
            notes = "修改附件结算方式信息",
            produces = "application/json, application/rbac",
            consumes = "application/json, application/rbac")
    public Response updateSettEleById(@RequestBody @Validated(value = ValidGroupUpdate.class)  Settlement settlement) {
        return Response.data(settEleService.updateById(settlement));
    }
}
